#!/bin/bash
# #######################################################################################
#
# Copyright (c) KylinSoft Co., Ltd. 2024. All rights reserved.
# SecureGuardian is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Description: Security Baseline Check Script for 2.4.2
#
# #######################################################################################

# 函数：检查SELinux是否处于强制模式
check_selinux_enforcing() {
    local current_mode=$(getenforce)
    local config_mode=$(grep "^SELINUX=" /etc/selinux/config | cut -d'=' -f2 | tr -d ' ')

    if [[ "$current_mode" != "Enforcing" || "$config_mode" != "enforcing" ]]; then
        echo "检测失败:SELinux未配置为强制模式。"
        return 1
    else
        echo "检测成功:SELinux已配置为强制模式。"
        return 0
    fi
}

# 调用函数并处理返回值
check_selinux_enforcing
exit $?

